package com.qf.weapon;

import java.util.Random;

public class Hero {
    //名称
    private String name;
    //力量
    private int power;
    //智力
    private int intelligence;
    //敏捷
    private int agile;

    //武器
    private Weapon weapon;


    public Hero() {
    }

    public Hero(String name, int power, int intelligence, int agile) {
        this.name = name;
        this.power = power;
        this.intelligence = intelligence;
        this.agile = agile;
    }

    public Weapon getWeapon() {
        return weapon;
    }

    public void setWeapon(Weapon weapon) {
        this.weapon = weapon;
    }

    public String getName() {
        return name;
    }

    public int weaponAttack() {

        if (weapon.getType() == 0) {
//            if (weapon.getName().equals("长剑")) return longSwordAttack();
            if (weapon instanceof LongSword) return longSwordAttack();
//            if (weapon.getName().equals("匕首")) return daggerAttack((Dagger) weapon);
            if (weapon instanceof Dagger) return daggerAttack((Dagger) weapon);

            // 近战武器攻击的伤害公式 =  徒手的伤害 + 武器的攻击力
            return this.attack() + weapon.getAtk();
        } else {
            if (weapon instanceof Staff) return staffAttack();
            // 远程武器的伤害公式 = Hero的敏捷 + 远程武器的攻击力
            return this.getAgile() + weapon.getAtk();
        }

    }

    private int staffAttack() {
        return (int) (this.getIntelligence()*1.5+this.getWeapon().getAtk());
    }

    /**
     * 为长剑添加武器特性，长剑的攻击伤害受到英雄的力量影响，使用长剑攻击伤害公式=长剑基础攻击力+英雄的力量*1.5
     *
     * @return
     */
    public int longSwordAttack() {
        return (int) (this.power + weapon.getAtk() + power * 1.5);
    }

    public int daggerAttack(Dagger weapon) {
        Random random = new Random();
        int r = random.nextInt(2);

        switch (r) {
            case 1:
                return (int) ((weapon.getAtk() + this.power) * weapon.getSpr());
            case 0:
                return (int) (weapon.getAtk() + this.power);
            default:
                return 0;
        }


    }

    /**
     * 徒手攻击
     *
     * @return
     */
    public int attack() {
        Random random = new Random();
        // min
        int min = (int) (power * 0.8);
        // max
        int max = (int) (power * 1.2);
        // [min,max] 产生一个随机数
        // [10,20]
        int result = random.nextInt((max - min) + 1) + min;
        return result;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getPower() {
        return power;
    }

    public void setPower(int power) {
        this.power = power;
    }

    public int getIntelligence() {
        return intelligence;
    }

    public void setIntelligence(int intelligence) {
        this.intelligence = intelligence;
    }

    public int getAgile() {
        return agile;
    }

    public void setAgile(int agile) {
        this.agile = agile;
    }
}
